package com.bindatax.biz.etl.create;

import com.bindatax.biz.etl.BinDataxBoot;
import com.bindatax.core.task.DataTaskPool;

import java.util.Properties;

public class JavaTxtUtil {
    private Properties sysPros = null;
    private Properties dsPoolPros = null;
    private Properties logPros = null;
    private DataTaskPool dataTaskPool = null;

    public void stopAll() {
        if( dataTaskPool != null ){
            dataTaskPool.stopAllTask();
            dataTaskPool = null;
        }
    }

    public void aaaaaa(String[] args) {
        Object[] r = new Object[]{};
        boolean first = true;
        if (r == null) {
            if( dataTaskPool != null ){
                dataTaskPool.waitDataTaskFinished();
            }
            //setOutputDone();
            return;
        }
        if (first){
            first = false;
            sysPros = new Properties();
            sysPros.put( "trans.concurrency.query.minSize" ,  "2" );
            sysPros.put( "sys.version" ,  "3.1.1" );
            sysPros.put( "trans.log.system.type" ,  "log4j" );
            dsPoolPros = new Properties();
            dsPoolPros.put( "dataSource.auto-commit" ,  "true" );
            dsPoolPros.put( "dataSource.max-lifetime" ,  "28740000" );
            dsPoolPros.put( "dataSource.pool-name" ,  "DataTaskConnPool" );
            dsPoolPros.put( "dataSource.idle-timeout" ,  "600000" );
            dsPoolPros.put( "dataSource.maximum-pool-size" ,  "200" );
            dsPoolPros.put( "dataSource.minimum-idle" ,  "5" );
            dsPoolPros.put( "dataSource.connection-timeout" ,  "30000" );
            logPros = new Properties();
            logPros.put( "log4j.appender.info.Threshold" ,  "INFO" );
            logPros.put( "log4j.appender.console.Target" ,  "System.out" );
            logPros.put( "log4j.appender.debug.Append" ,  "true" );
            logPros.put( "log4j.appender.warn.layout.ConversionPattern" ,  "%d{yyyy-MM-dd HH:mm:ss} - %35.35c - %30.30t - %p - [%rms]: %m%n" );
            logPros.put( "log4j.appender.console" ,  "org.apache.log4j.ConsoleAppender" );
            logPros.put( "log4j.appender.warn" ,  "org.apache.log4j.DailyRollingFileAppender" );
            logPros.put( "log4j.appender.console_file.Append" ,  "true" );
            logPros.put( "log4j.appender.console.layout" ,  "org.apache.log4j.PatternLayout" );
            logPros.put( "log4j.appender.warn.Threshold" ,  "WARN" );
            logPros.put( "log4j.appender.warn.File" ,  "logs/bindatax-warn.log" );
            logPros.put( "log4j.appender.warn.layout" ,  "org.apache.log4j.PatternLayout" );
            logPros.put( "log4j.appender.error.layout" ,  "org.apache.log4j.PatternLayout" );
            logPros.put( "log4j.appender.debug.layout.ConversionPattern" ,  "%d{yyyy-MM-dd HH:mm:ss} - %35.35c - %30.30t - %p - [%rms]: %m%n" );
            logPros.put( "log4j.appender.console_file.File" ,  "logs/bindatax-console.log" );
            logPros.put( "log4j.appender.info.Append" ,  "true" );
            logPros.put( "log4j.appender.console_file.layout.ConversionPattern" ,  "%d{yyyy-MM-dd HH:mm:ss} - %35.35c - %30.30t - %p - [%rms]: %m%n" );
            logPros.put( "log4j.rootLogger" ,  "TRACE,error,warn,info,debug,console,console_file" );
            logPros.put( "log4j.appender.debug.layout" ,  "org.apache.log4j.PatternLayout" );
            logPros.put( "log4j.appender.console_file.layout" ,  "org.apache.log4j.PatternLayout" );
            logPros.put( "log4j.appender.error.layout.ConversionPattern" ,  "%d{yyyy-MM-dd HH:mm:ss} - %35.35c - %30.30t - %p - [%rms]: %m%n" );
            logPros.put( "log4j.appender.error.File" ,  "logs/bindatax-error.log" );
            logPros.put( "log4j.appender.console_file.Threshold" ,  "TRACE" );
            logPros.put( "log4j.appender.console_file" ,  "org.apache.log4j.DailyRollingFileAppender" );
            logPros.put( "log4j.appender.debug" ,  "org.apache.log4j.DailyRollingFileAppender" );
            logPros.put( "log4j.appender.error" ,  "org.apache.log4j.DailyRollingFileAppender" );
            logPros.put( "log4j.appender.info.File" ,  "logs/bindatax-info.log" );
            logPros.put( "log4j.appender.info.layout" ,  "org.apache.log4j.PatternLayout" );
            logPros.put( "log4j.appender.info" ,  "org.apache.log4j.DailyRollingFileAppender" );
            logPros.put( "log4j.appender.console.Threshold" ,  "TRACE" );
            logPros.put( "log4j.appender.warn.Append" ,  "true" );
            logPros.put( "log4j.appender.error.Threshold" ,  "ERROR" );
            logPros.put( "log4j.appender.console.layout.ConversionPattern" ,  "%d{yyyy-MM-dd HH:mm:ss} - %35.35c - %30.30t - %p - [%rms]: %m%n" );
            logPros.put( "log4j.appender.debug.File" ,  "logs/bindatax-debug.log" );
            logPros.put( "log4j.appender.error.Append" ,  "true" );
            logPros.put( "log4j.appender.info.layout.ConversionPattern" ,  "%d{yyyy-MM-dd HH:mm:ss} - %35.35c - %30.30t - %p - [%rms]: %m%n" );
            logPros.put( "log4j.appender.debug.Threshold" ,  "DEBUG" );
            dataTaskPool = BinDataxBoot.init(sysPros,logPros,dsPoolPros);
        }
        Properties taskMetaConfig = new Properties();
        //taskMetaConfig.put( "biz.zzzzzzzz" , get(Fields.In, "zzzzzzzz").getString(r) );
        taskMetaConfig.put( "trans.write.segment.batch.size" ,  "200" );
        taskMetaConfig.put( "trans.fail.try.num" ,  "3" );
        taskMetaConfig.put( "db.target.field.key.names" ,  "" );
        taskMetaConfig.put( "trans.write.segment.number" ,  "3" );
        taskMetaConfig.put( "db.target.validationQuery" ,  "SELECT 1 FROM dual" );
        taskMetaConfig.put( "db.target.schema" ,  "TEST_GS_SXYTH" );
        taskMetaConfig.put( "db.source.user" ,  "SYSTEM" );
        taskMetaConfig.put( "db.log.user" ,  "TEST_GS_SXYTH" );
        taskMetaConfig.put( "db.log.url" ,  "jdbc:oracle:thin:@10.10.80.234:1521:helowin" );
        taskMetaConfig.put( "db.log.pwd" ,  "TEST_GS_SXYTH" );
        taskMetaConfig.put( "db.target.url" ,  "jdbc:oracle:thin:@10.10.80.234:1521:helowin" );
        taskMetaConfig.put( "db.log.driver" ,  "oracle.jdbc.driver.OracleDriver" );
        taskMetaConfig.put( "db.source.url" ,  "jdbc:oracle:thin:@10.10.80.232:1521:orcl" );
        taskMetaConfig.put( "db.query.sql" ,  "SELECT * FROM TEST.AC02_JS1 WHERE AAZ159 <= 1000" );
        taskMetaConfig.put( "db.source.schema" ,  "TEST" );
        taskMetaConfig.put( "db.target.table.name" ,  "TEST_AC02_JS1_DATA" );
        taskMetaConfig.put( "db.target.user" ,  "TEST_GS_SXYTH" );
        taskMetaConfig.put( "db.target.pwd" ,  "TEST_GS_SXYTH" );
        taskMetaConfig.put( "db.target.field.key.autoCheck" ,  "y" );
        taskMetaConfig.put( "db.target.driver" ,  "oracle.jdbc.driver.OracleDriver" );
        taskMetaConfig.put( "db.source.pwd" ,  "oracle232" );
        taskMetaConfig.put( "db.query.schema" ,  "TEST" );
        taskMetaConfig.put( "db.log.schema" ,  "TEST_GS_SXYTH" );
        taskMetaConfig.put( "trans.write.await.outTime" ,  "60" );
        taskMetaConfig.put( "db.query.field.incrementTimeName" ,  "" );
        taskMetaConfig.put( "trans.error.ignore.continue" ,  "n" );
        taskMetaConfig.put( "db.log.validationQuery" ,  "SELECT 1 FROM dual" );
        taskMetaConfig.put( "db.source.validationQuery" ,  "SELECT 1 FROM dual" );
        taskMetaConfig.put( "trans.fail.try.interval" ,  "3" );
        taskMetaConfig.put( "db.source.driver" ,  "oracle.jdbc.driver.OracleDriver" );
        taskMetaConfig.put( "trans.statistics.open" ,  "n" );
        taskMetaConfig.put( "trans.log.out.error.ignore.maxSize" ,  "10" );
        BinDataxBoot.addTask( dataTaskPool , taskMetaConfig , this );
        //putRow(data.outputRowMeta, r);
        //return true;
    }
}
